define(["request"], function(request) {

	var upload = {}

	// 上传文件
	upload.Upload = function(files, successFunc) {
		if(files.length <= 0) {
			mui.toast("没有添加上传文件！");
			return;
		}

		if(typeof(files) == 'string') {
			files = [files]
		}

		var wt = plus.nativeUI.showWaiting();
		var task = plus.uploader.createUpload(request.checkUrl("file/upload"), {
				method: "POST",
				timeout: 60000,
			},
			function(t, status) { //上传完成
				if(status == 200) {
					plus.nativeUI.toast("上传成功");
					wt.close();
					var obj = JSON.parse(t.responseText); //由JSON字符串转换为JSON对象
					if(obj.state) {
						successFunc(obj.data)
					} else {
						plus.nativeUI.toast(obj.error);
					}
				} else {
					plus.nativeUI.toast("连接超时，请检查您的网络设置");
					wt.close();
				}
			}
		);
		for(var i = 0; i < files.length; i++) {
			var f = files[i];
			task.addFile(f, {
				key: "img" + i
			});
		}
		task.start();
	};
	
	return upload;
});